<?php

include "../../../lib/start.php";
check_session();
check_permission(DOC_PERM);

if(!isset($_REQUEST['offset']))
    $offset = 0;
else
    $offset = $_REQUEST['offset'];

$limit = 15;

$sel_works = "SELECT id_work, anno, _classe AS classe, autore, titolo, abstract FROM stud_works WHERE owner = ".$_SESSION['__user__']->getUid()." ORDER BY data_inserimento DESC ";
//print $sel_works;

if(!isset($_REQUEST['second'])){
    $res_works = $db->execute($sel_works);
    //print $sel_links;
    $count = $res_works->num_rows;
    //print $count;
    $_SESSION['count_files'] = $count;
}
else{
    $sel_works .= " LIMIT $limit OFFSET $offset";
    $res_works = $db->execute($sel_works);
}
//print $query;
if($offset == 0)
    $page = 1;
else
    $page = ($offset / $limit) + 1;

$pagine = ceil($_SESSION['count_files'] / $limit);
if($pagine < 1)
    $pagine = 1;

// dati per la paginazione (navigate.php)
$colspan = 5;
$link = basename($_SERVER['PHP_SELF']);
$count_name = "count_files";

include "student_works.html.php";

?>